package com.example.hotel_lxy.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.example.hotel_lxy.R;
import com.ysxsoft.common_base.utils.DisplayUtils;
import com.ysxsoft.common_base.utils.WebViewUtils;

import uk.co.senab.photoview.PhotoView;
import uk.co.senab.photoview.PhotoViewAttacher;


/**
* 隐私协议
* create by Sincerly on 9999/9/9 0009
**/
public class WebDialog extends Dialog {
    private Context mContext;
    private OnDialogClickListener listener;
    public WebDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        this.mContext = context;
//        init();
    }

    private View init() {
        View view = View.inflate(mContext, R.layout.web_dialog, null);
        TextView title=view.findViewById(R.id.title);
        TextView text_no=view.findViewById(R.id.text_no);
        TextView text_yes=view.findViewById(R.id.text_yes);
        text_no.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onPositiveClick("1");
                dismiss();
            }
        });
        text_yes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onPositiveClick("2");
                dismiss();
            }
        });
        WebView webView=view.findViewById(R.id.webView);
        WebViewUtils.init(webView);
        webView.loadUrl("http://api.luxiaoyi.vip/about/2.html");
        title.setText("用户隐私政策概要");
        return view;
    }

    @Override
    protected void onStart() {
        super.onStart();

    }

    @Override
    protected void onStop() {
        super.onStop();

    }



    public OnDialogClickListener getListener() {
        return listener;
    }

    public void setListener(OnDialogClickListener listener) {
        this.listener = listener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setCanceledOnTouchOutside(false);
        setContentView(init());
    }

    public void showDialog() {
        if (!isShowing()) {
            show();
            WindowManager.LayoutParams lp = getWindow().getAttributes();
//            lp.height = DisplayUtils.getDisplayWidth(mContext) * 5 / 5;
//            lp.width = DisplayUtils.getDisplayWidth(mContext) * 10 / 10;
//            lp.height = WindowManager.LayoutParams.MATCH_PARENT;
//            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.width = DisplayUtils.getDisplayWidth(mContext) * 8 / 10;
            lp.height = DisplayUtils.getDisplayHeight(mContext) * 6 / 10;
            getWindow().setAttributes(lp);
            getWindow().setGravity(Gravity.CENTER);
        }
    }

    public static WebDialog show(Context context, OnDialogClickListener listener) {
        WebDialog dialog = new WebDialog(context, R.style.BottomDialogStyle);
        dialog.setListener(listener);
        dialog.showDialog();
        return dialog;
    }

    public interface OnDialogClickListener {
        /**
         * 点击确定按钮事件
         */
        public void onPositiveClick(String s);
    }
}